// packageA/pages/city/city.js
const app = getApp();
Page({
  data: {
    curArea:{},
    hotList: [],
    list: [],
    indexList:[],
  },
  onReady() {
    // 获取当前地区
    let curArea=app.globalData.currentArea;
    this.setData({curArea})
    // 获取热门地区
    let areaList=app.globalData.areaList;
    let hotList=areaList.slice(0,7)
    this.setData({hotList})

    let list = [];
    for (var i = 0; i < 26; i++) {
      list.push(String.fromCharCode(97 + i))
    }
    list.map((item, index) => { //a-z 26字母  [a,b,c,.....]
      list[index] = {
        k: item,
        p:item.toLocaleUpperCase(),
        list: []
      }
      //[{k:'a',p:'A',list:[]},{k:'b',p:'b',list:[]}]
      areaList.map((obj) => {
        var p = obj.py.slice(0, 1);
        if (list[index].k === p) {
          list[index].list.push(obj)
        }
      })
    })
    var indexList = [];
    list.map((item,index)=>{
      indexList.push(item.p)
    })
    this.setData({list,indexList});
  },
  getCurrentCity(e){
    console.log("e:",e)
    let curArea=e.currentTarget.dataset.item;
    app.globalData.currentArea=curArea;
    // app.globalData.callBackEvent();
    this.setData({curArea})
    wx.switchTab({
      url: '/pages/index/index',
    })
  },
  onShareAppMessage: function (res){
    return {
      title: '电影之家',
      path: '/pages/index/index'
    }
  },
})